//
//  AXFCircleAniView.m
//  BEEQUICK
//
//  Created by admin on 21/11/2016.
//  Copyright © 2016 SevenGroup. All rights reserved.
//

#import "AXFCircleAniView.h"
#import "AXFCircleAniLayer.h"

@interface AXFCircleAniView ()<CAAnimationDelegate>

@property (nonatomic, strong) AXFCircleAniLayer *circleAniLayer;

@end

@implementation AXFCircleAniView

- (id)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		self.circleAniLayer = [AXFCircleAniLayer layer];
		self.circleAniLayer.frame = self.bounds;
		//像素大小比例
		self.circleAniLayer.contentsScale = [UIScreen mainScreen].scale;
		[self.layer addSublayer:self.circleAniLayer];
	}
	return self;
}

- (void)setProgress:(CGFloat)progress {
	CABasicAnimation * ani = [CABasicAnimation animationWithKeyPath:@"progress"];
	ani.duration = .5 * fabs(progress - _progress);
	ani.toValue = @(progress);
	ani.removedOnCompletion = YES;
	ani.fillMode = kCAFillModeForwards;
	ani.delegate = self;
	[self.circleAniLayer addAnimation:ani forKey:@"progressAni"];
	
	_progress = progress;
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
	self.circleAniLayer.progress = self.progress;
}

- (void)setupUI {
	self.backgroundColor = UIColor.whiteColor;
	
	UILabel *descLabel = [[UILabel alloc] init];
	UILabel *creditsLabel = [[UILabel alloc] init];
	
	descLabel.text = @"可用积分";
	descLabel.font = [UIFont systemFontOfSize:12];
	descLabel.textColor = [UIColor cz_colorWithHex:0x999999];
	
	creditsLabel.text = [NSString stringWithFormat:@"%d", 0];
	creditsLabel.font = [UIFont systemFontOfSize:21];
	creditsLabel.textColor = [UIColor cz_colorWithHex:0x999999];
	
	[self addSubview:descLabel];
	[self addSubview:creditsLabel];
	
	[descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.offset(0);
		make.top.offset(73);
	}];
	
	[creditsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(descLabel);
		make.top.equalTo(descLabel.mas_bottom).offset(7);
	}];
}

//- (void)drawRect:(CGRect)rect {
//	[self drawCricleWithRadius:75 color:[UIColor cz_colorWithHex:0xdddddd]];
//	[self drawCricleWithRadius:56 color:[UIColor cz_colorWithHex:0xc7c7c7]];
//	[self drawCricleWithRadius:45 color:[UIColor whiteColor]];
//}
//
//- (void)drawCricleWithRadius:(CGFloat)r color:(UIColor *)color {
//	CGPoint center = CGPointMake(0.5 * kSCREENWIDTH, 93);
//	CGFloat radius = r;
//	CGFloat startAngle = 0;
//	CGFloat endAngle = 2 * M_PI;
//	
//	_endAngle = endAngle;
//	UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:_endAngle clockwise:YES];
//	
//	[color set];
//	[path fill];
//}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
